﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LiterizerApp {
    class KeyPunch {
        public KeyPunch(int key, int mask) {
            this.key = key;
            this.mask = mask;
        }
        public KeyPunch(int key) {
            this.key = key;
            this.mask = 0;
        }

        public readonly int key;
        public readonly int mask;
    }
    class KeyPunchComparator : IEqualityComparer<KeyPunch> {
        public bool Equals(KeyPunch p1, KeyPunch p2) {
            return p1.key == p2.key && p1.mask == p2.mask;
        }
        public int GetHashCode(KeyPunch p) {
            return p.key * 31 + p.mask;
        }
    }
    public partial class LiterizerMain : Form {
        private Dictionary<KeyPunch, string> keys = new Dictionary<KeyPunch, string>(new KeyPunchComparator());
        private HashSet<char> chars = new HashSet<char>();
        public LiterizerMain() {
            InitializeComponent();
            keys.Add(new KeyPunch((int)Keys.B), "ბ");
            keys.Add(new KeyPunch((int)Keys.B, (int)Keys.Shift), "β");
            keys.Add(new KeyPunch((int)Keys.B, (int)Keys.Alt), "ß");

            keys.Add(new KeyPunch((int)Keys.A), "ა");
            keys.Add(new KeyPunch((int)Keys.A, (int)Keys.Shift), "α");
            keys.Add(new KeyPunch((int)Keys.A, (int)Keys.Alt), "ա");

            keys.Add(new KeyPunch((int)Keys.D), "დ");
            keys.Add(new KeyPunch((int)Keys.D, (int)Keys.Shift), "δ");
            keys.Add(new KeyPunch((int)Keys.D, (int)Keys.Alt), "դ");

            chars.Add('b');
            chars.Add('a');
            chars.Add('d');
            chars.Add('B');
            chars.Add('A');
            chars.Add('D');
            txtMain.Font = new System.Drawing.Font("Sylfaen", 11.5F);
        }

        private void txtMain_KeyPress(object sender, KeyPressEventArgs e) {
            if(chars.Contains(e.KeyChar)) e.Handled = true;
        }
        private void say(string what) {
            txtMain.SelectedText = what;
        }
        private void txtMain_KeyUp(object sender, KeyEventArgs e) {
            KeyPunch p = new KeyPunch((int)e.KeyCode, (int)e.Modifiers);
            string s;
            if (keys.TryGetValue(p, out s)) {
                say(s); e.Handled = true;
            }
            /*if (e.KeyCode == Keys.B && e.Modifiers == 0) {
                say("ბ"); e.Handled = true;
            }
            else if (e.KeyCode == Keys.B && e.Modifiers == Keys.Shift) {
                say("β"); e.Handled = true;
            }
            else if (e.KeyCode == Keys.B && e.Modifiers == Keys.Alt) {
                say("ß"); e.Handled = true;
            }*/
        }

    }
}
